<?LassoScript 

	
	local('parsedNav'=er_urlReq(-path=Response_FilePath));
	local('navSize'=#parsedNav->size);
	
	var(
	'navString'='',
	'thisUrl'=string);
	
	iterate(#parsedNav, var('thisparam'));
		var('pname'='param' + loop_count);
		var(var('pname')=$thisparam);
		$navString += $thisparam + '/';
	/iterate;
	
	$navString->removeTrailing('/');
	er_makeParam('param2', '');
	
	var('currentPage' = #parsedNav->last);
	var('currentSection' = var('param1'));
	
	
	//.................................................................................//
	//.................................................................................//
	// param 1 is the controller
	// param 2 is the model, model then calls the view
	// param 3 is options, options can be additional variables or methods to pass to a model
	// SCAFFOLDING: all scaffolding resides in the _app folder
	
	// _admin is a prtected location and must not be messed with
	// it will be the scafolding for the built-in CMS and engineRoom creation tool


	if(#navSize != 0);
	
		select($param1);
		
		case('page');
				// optional static page server
				!var_defined('param2') ? redirect_url($domain);
				
				$thisUrl = '/_app/_static/dsp_'+$param2+'.lasso';
				//$thisUrl;
				inline($connection);
					file_exists($thisUrl) 
						? include($thisUrl)
						| include($defaultErrorDisplay);
				/inline;
			
		
		case;
			// first we find if there is a controller ready to be found
			// the er_crawl reads all available folders (controllers) in the _app folder
			if(er_crawl->find($param1)->first != '');
				var('thisEngine' = $er_dir + '/_app/'+$param1+'/'+$param1+'_engine.lasso');
				var('thisEnginePage' = $er_dir + '/_app/'+$param1+'/dsp_'+$param1+'.lasso');
				$param2 !='' ? var('thisEnginePageSub' = $er_dir + '/_app/'+$param1+'/dsp_'+$param2+'.lasso');
				
				var('currentpath' = $er_dir + '/_app/'+$param1+'/');
				
				if(file_exists($thisEngine));
				
					// check to see if we have a valid engine controller file
					// if not we will look for a static page to served from db content in pageEngine.lasso file
					// {this is the typical default pass-through file}
					include($er_dir + '/_app/'+$param1+'/'+$param1+'_engine.lasso');
					
				else;
					
					$param2 != '' ? $thisEnginePage = $thisEnginePageSub;
					
					file_exists($thisEnginePage) 
					? include($thisEnginePage) 
					| include($er_dir + '/_config/lib/pageEngine.lasso');
					
				/if;
				
			else;
				
				// if nothing found look for db dirven content here...
				include($er_dir + '/_config/lib/pageEngine.lasso');
			/if;
		/select;

	else;
		// lowest common denominator, aka the home page
		//	default home page
			$useLayout = 'home';
		// 	use useLayout defines which layout to use at an given point in time
		
		//	include('/_config/lib/qry_defaultHome.lasso');
		// 	the query above is used primarily when the home page is defined in the page manager CMS system
		// 	the page manager has a function to write out a static page for better caching
		// 	and to ease the hits on the database on a heavy traffic site
		
		include($er_dir + '/_app/home/dsp_Home.lasso');

	/if;

?>